#include <p18f4550.h>

#include "ADC.h"
#include "CPU.h"
#include "definesAndDataTypes.h"

void main()
{initializeCPU();
initializeADC();
re_states=RESET;
OUT_PORT=RESET_WARNING;
while(1)
{re_states=GET_INPUT;
 if(AUTO!=re_states)
	{
		re_states2=LIGHTSOFF;
	}
	switch(re_states)
	{
	case OFF:
	OUT_PORT=TURN_OFF;
	break;
	case AUTO:
		GET_ADC_INFO;
		switch(re_states2)
		{
		case LIGHTSOFF:
		if(ADRESH>PERC60)
		{OUT_PORT=TURN_PARKLAMPS;re_states2=HALFLIGHT;}
		
		break;
		
		case HALFLIGHT:
		if(ADRESH<PERC40)
		{OUT_PORT=TURN_OFF;re_states2=LIGHTSOFF;}
		if(ADC_RESULT>PERC80)
		{OUT_PORT=TURN_ALLLAMPS;re_states2=LIGHTSON;}
		break;

		case LIGHTSON:
		if(ADRESH<PERC80)
		{OUT_PORT=TURN_PARKLAMPS;re_states2=HALFLIGHT;}
		break;
		}

	break;
	case HEADLAMPS:
	OUT_PORT=TURN_HEADLAMPS;
	break;
	case PARKLAMPS:
	OUT_PORT=TURN_PARKLAMPS;
	break;
	}
	


}
}
